import json
import os

def parse_jsonl(input_file, output_dir, max_lines=None):
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    with open(input_file, 'r', encoding='utf-8') as f:
        for i, line in enumerate(f):
            if max_lines is not None and i >= max_lines:
                break
            data = json.loads(line)
            output_file = os.path.join(output_dir, f'line_{i + 1}.json')
            with open(output_file, 'w', encoding='utf-8') as out_f:
                json.dump(data, out_f, ensure_ascii=False, indent=4)

if __name__ == "__main__":
    input_file = '/disk0/wyf/Project/zz_static_project/dataset/CodeXGLUE/Code-Code/Clone-detection-BigCloneBench/dataset/data.jsonl'
    output_dir = '/disk0/wyf/Project/zz_static_project/dataset/CodeXGLUE_Code-Code_Clone-detection-BigCloneBench'
    max_lines = 50  # Set to None to parse all lines
    parse_jsonl(input_file, output_dir, max_lines)